// import { changeFormData } from 'common/js/utils'

export const ajax = (url, data, option = {}) => {
  return new Promise((resolve, reject) => {
    // let cloneData = data
    // if (!option.isNoChangeFormData) {
    //   cloneData = changeFormData(cloneData)
    // }

    const realUserInfo = wx.getStorageSync('realUserInfo')
    const header = {
      'Content-type': 'application/x-www-form-urlencoded'
    }
    if (realUserInfo) {
      header.Cookie = `SESSION=${realUserInfo.sessionId}`
      header.token = realUserInfo.token
    }
    wx.request({
      url,
      data,
      method: 'POST',
      header: {
        ...header,
        ...option.header
      },
      success: res => {
        resolve(res.data)
      },
      fail: err => {
        resolve({
          msg: err
        })
      }
    })
  })
}
